package org.p2psimulator.entity.overlaynetwork.routingtable;

import java.util.HashSet;
import java.util.Set;
import org.p2psimulator.entity.Id;

public class GnutellaRoutingTable extends FloodRoutingTable {

	private Set<Id> table;

	private int maxSize;

	public  GnutellaRoutingTable(int maxSize){
		this.table = new HashSet<Id>();
		this.maxSize = maxSize;
	}

	public GnutellaRoutingTable(){
		this.table = new HashSet<Id>();
		this.maxSize = 10000;
	}
	@Override
	public synchronized void clear() {
		this.table.clear();

	}

	@Override
	public synchronized boolean contains(Id peer) {
		return this.table.contains(peer);
	}

	@Override
	public synchronized boolean deletePeer(Id peer) {
		return this.table.remove(peer);
	}

	@Override
	public synchronized void insertNeighbor(Id peer) {
		if (table.size() < maxSize & !table.contains(peer)){
			table.add(peer);
                }

	}

	public synchronized int size() {
		return this.table.size();

	}
	public int getMaxSize() {
		return maxSize;
	}

	public void setMaxSize(int maxSize) {
		this.maxSize = maxSize;
	}

	public synchronized  Set<Id> getNeighbors() {
		return table;
	}

	public synchronized void setNeighbors(Set<Id> table) {
		this.table = table;
	}

}
